package com.example.swimmingpool.service.employee;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.swimmingpool.entity.employee.Employee;
import com.example.swimmingpool.mapper.employee.EmployeeMapper;
import com.example.swimmingpool.qo.employee.EmployeeQo;
import org.springframework.stereotype.Service;

@Service
public class EmployeeService extends ServiceImpl<EmployeeMapper, Employee> {

    public IPage<Employee> listEmployee(EmployeeQo qo) {
        IPage<Employee> pages = new LambdaQueryChainWrapper<>(this.getBaseMapper())
                .eq(ObjectUtil.isNotNull(qo.getId()), Employee::getId, qo.getId())
                .like(ObjectUtil.isNotNull(qo.getName()), Employee::getName, qo.getName())
                .like(ObjectUtil.isNotNull(qo.getAddress()), Employee::getAddress, qo.getAddress())
                .like(ObjectUtil.isNotNull(qo.getPhone()), Employee::getPhone, qo.getPhone())
                .like(ObjectUtil.isNotNull(qo.getWork()), Employee::getWork, qo.getWork())
                .ge(ObjectUtil.isNotNull(qo.getStartBirthday()), Employee::getBirthday, qo.getStartBirthday())
                .le(ObjectUtil.isNotNull(qo.getEndBirthday()), Employee::getBirthday, qo.getEndBirthday())
                .page(new Page<>(qo.getCurrent(), qo.getSize()));
        return pages;

    }


}
